package org.bai.miaoshaproject.response;

import lombok.Data;
import org.bai.miaoshaproject.error.EmBusinessError;

/**
 * ClassName CommonReturnType
 *
 * @author Bai
 * @version 1.0
 * @date 2019/5/27 0027 下午 23:12
 **/

@Data
public class CommonReturnType<T> {

    private String status;
    private Integer code;
    private String msg;
    private T data;

    private CommonReturnType(String status){
        this.status = status;
    }

    public CommonReturnType(String status, Integer code, String msg) {
        this.status = status;
        this.code = code;
        this.msg = msg;
    }

    public CommonReturnType(String status, Integer code, String msg, T data) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static<T> CommonReturnType<T> creatSuccess(){
        return new CommonReturnType<T>("success");
    }

    public static<T> CommonReturnType<T> creatSuccess(T result){
        return new CommonReturnType<T>("success", 0, "", result);
    }

    public static<T> CommonReturnType<T> creatError(){
        return new CommonReturnType<T>("error");
    }

    public static<T> CommonReturnType<T> creatError(EmBusinessError emBusinessError){
        return new CommonReturnType<T>("error", emBusinessError.getErrorCode(), emBusinessError.getErrorMsg());
    }

    public static<T> CommonReturnType<T> creatError(Integer code, String msg){
        return new CommonReturnType<T>("error", code, msg);
    }

    public static<T> CommonReturnType<T> creatError(EmBusinessError emBusinessError, String errorMsg){
        return new CommonReturnType<T>("error", emBusinessError.getErrorCode(), errorMsg);
    }
}
